package com.bookseek.xreader.views;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.bookseek.xreader.R;
import com.bookseek.xreader.utils.DLog;
import com.bookseek.xreader.views.helper.SearchViewHelper;

public class SearchContentActivity extends AppCompatActivity implements View.OnClickListener {

    private SearchViewHelper searchHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_search_content);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        ImageView clearButton = findViewById(R.id.iv_clear);
        // 初始化搜索栏组件
        EditText searchEditText = findViewById(R.id.et_search);
        // 创建搜索助手
        searchHelper = new SearchViewHelper(this, searchEditText, clearButton);

        // 设置搜索监听
        searchHelper.setOnSearchListener(new SearchViewHelper.OnSearchListener() {
            @Override
            public void onSearch(String query) {
                // 处理搜索逻辑
                Toast.makeText(SearchContentActivity.this, "搜索: " + query, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onTextChanged(String text) {
                // 处理文本变化（如实时搜索建议）
                // Log.d("Search", "文本变化: " + text);
                DLog.info("Search:","文本变化: " + text);
            }
        });


    }

    @Override
    public void onClick(View view) {

    }
}